using System;
using Sedna.Core.Support;
using Sedna.Domain.Orders;

namespace Sedna.API.Wrapper
{
    /// <summary>
    /// This is an object that wraps information about Safekeeping orders. 
    /// </summary>
    [Serializable]
    public abstract class InventoryOrderWrapper
    {
        # region Fields

        protected String flag;
        private String orderNumber;
        private String referenceNumber;
        private DateTime orderDate = DateTime.Now;
        private String comment;

        # endregion

        # region Constructors

        public InventoryOrderWrapper(Order order)
        {
            Assert.IsNotNull(order, "Can't create wrapper from NULL order");

            orderNumber = order.OrderNumber;
            referenceNumber = order.ReferenceNumber;
            orderDate = order.OrderDate;
            comment = order.Comment;
            
        }   
        
        # endregion

        public static InventoryOrderWrapper Create(Order order, bool isReceiving)
        {
            InventoryOrderWrapper result = null;
            if (order is InventoryReceivingOrder)
                result = new InventoryReceivingOrderWrapper(order);
            else if (order is InventoryOwnershipTransferOrder && isReceiving)
                result = new InventoryReceivingOrderWrapper(order);
            else if (order is InventoryOwnershipTransferOrder && !isReceiving)
                result = new InventoryShippingOrderWrapper(order);
            else if (order is InventoryShippingOrder)
                result = new InventoryShippingOrderWrapper(order);
            
            result.InitCustom(order);
            return result;
        }
        
        # region Properties

        public string OrderNumber
        {
            get { return orderNumber; }
        }

        public string ReferenceNumber
        {
            get { return referenceNumber; }
        }

        public DateTime OrderDate
        {
            get { return orderDate; }
        }

        public string Comment
        {
            get { return comment; }
        }

        public string Flag
        {
            get { return flag; }
        }

        # endregion

        protected abstract void InitCustom(Order order);
        
    }
}
